package com.dxd.onlineshop.mapper;

import com.dxd.onlineshop.pojo.UserFeedback;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserFeedbackMapper {

    //创建反馈
    @Insert("INSERT INTO user_feedback (user_id, feedback_type, feedback_content, created_at) " +
            "VALUES (#{userId}, #{feedbackType}, #{feedbackContent}, #{createdAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(UserFeedback feedback);

    //根据ID获取反馈
    @Select("SELECT * FROM user_feedback WHERE id = #{id}")
    UserFeedback selectById(Long id);

    //获取用户所有反馈
    @Select("SELECT * FROM user_feedback WHERE user_id = #{userId}")
    List<UserFeedback> selectByUserId(Integer userId);

    //获取全部反馈
    @Select("SELECT * FROM user_feedback")
    List<UserFeedback> selectAll();

    //根据特定类型获取反馈
    @Select("SELECT * FROM user_feedback WHERE feedback_type = #{feedbackType}")
    List<UserFeedback> selectByType(UserFeedback.FeedbackType feedbackType);

    //更新反馈
    @Update("UPDATE user_feedback SET feedback_content = #{feedbackContent} WHERE id = #{id}")
    int update(UserFeedback feedback);

    //删除反馈
    @Delete("DELETE FROM user_feedback WHERE id = #{id}")
    int deleteById(Long id);

    //搜索反馈
    @Select("SELECT * FROM user_feedback WHERE user_id = #{userId} AND feedback_content LIKE CONCAT('%', #{keyword}, '%')")
    List<UserFeedback> searchByContentAndUserId(@Param("keyword") String keyword, @Param("userId") Integer userId);
}